/**
 * Created with JetBrains WebStorm.
 * User: Eric
 * Date: 02/02/13
 * Time: 17:33
 * To change this template use File | Settings | File Templates.
 *
 *
 */


/*
 * this is a test file for design a Dao pattern like in Java.
 * This is the model of user
 */
var Personage = require("./Personage");
var User = function User(){



}

User.prototype = {
    initialize : function() {
        this.id;
        this.pseudo,
        this.email,
        this.password,
        this.firstname,
        this.lastname,
        this.confirmation_token,
        this.confirmation_date_limit,
        this.actif,
        this.personage,
        this.type
    },

    /*
     *This function will take the rows of the SQL query and hydrate the user
     */
    init : function(parameters){
        this.id = parameters.id;
        this.pseudo = parameters.pseudo;
        this.email = parameters.email;
        this.password = parameters.password;
        this.firstname = parameters.firstname;
        this.lastname = parameters.lastname;
        this.confirmation_token = parameters.confirmation_token;

        if (parameters.confirmation_date_limit != null)
            this.confirmation_date_limit = new Date(parameters.confirmation_date_limit);
        else
            this.confirmation_date_limit = null;

        this.actif = parameters.actif;
        this.type = parameters.type;


        if(parameters.personage == null){
            this.personage = null;
        }else{


            this.personage = new Personage();
            this.personage.init(parameters.personage);
        }
    },

    getPersonageForPersist : function(){


        if(this.personage == null){

            return null;
        }
        if(this.personage.id == undefined){

            return this.personage;
        }else{
            return this.personage.id;
        }

    }
}


/*
 * We export the class user so we ca use it after requiring this file.
 */
module.exports = User;